package com.circle.interests.biz.controller;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.circle.common.core.constant.Constant;
import com.circle.common.core.utils.R;
import com.circle.interests.biz.entity.PrizeHonglianProduct;
import com.circle.interests.biz.request.HongLianProductPageRequest;
import com.circle.interests.biz.service.IPrizeHonglianProductService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhou
 * @date 2021/12/6
 */
@Slf4j
@Api(tags = {"鸿联虚拟产品（pc端接口）"})
@RestController
@RequestMapping("honglian")
@ApiSupport(author = "周福寿")
public class PrizeHongLianProductController {

    @Resource
    private IPrizeHonglianProductService prizeHonglianProductService;

    @ApiOperation("鸿联产品分页列表")
    @PostMapping("/page")
    public R<IPage<PrizeHonglianProduct>> page(@RequestBody HongLianProductPageRequest form) {
        LambdaQueryWrapper<PrizeHonglianProduct> query = new LambdaQueryWrapper<>();
        query.eq(form.getUseType() != null, PrizeHonglianProduct::getUseType, form.getUseType())
                .like(StrUtil.isNotBlank(form.getProductName()), PrizeHonglianProduct::getProductName, form.getProductName());
        Page<PrizeHonglianProduct> page = new Page<>();
        page.setCurrent(Convert.toLong(form.getPageNo(), Constant.PAGE_NO_1));
        page.setSize(Convert.toLong(form.getPageSize(), Constant.PAGE_SIZE_25));
        return R.success(prizeHonglianProductService.page(page, query));
    }

    @ApiOperation("查询鸿联产品列表")
    @PostMapping("/listProduct")
    public R<List<PrizeHonglianProduct>> listProduct() {
        return R.success(prizeHonglianProductService.list());
    }

}
